
import { getServicePeople, getGender, selectDeptTree, serviceTypeAll } from '../services/api';
import {Message} from 'antd'
export default {

  namespace: 'example',

  state: {
    height: document.body.clientHeight, //页面高
    width: document.body.clientWidth, //页面宽
    personalModal: false, //服务人员管理侧滑控制
    addModal:false,  //新增修改
    distributeModal:false,   //分配人员
    oldDetailModal:false,   //老人详情
    areaInfo: [], //区域信息
    serviceType: [], //服务类型
    servicePersons: [], //服务人员
    gender: [], //性别
  },

  subscriptions: {
    setup({ dispatch, history }) {  // eslint-disable-line
    },
  },

  effects: {
    *fetch({ payload }, { call, put }) {  // eslint-disable-line
      yield put({ type: 'save' });
    },
    /** 
     * 
    */
    *setPersonalModal({ res }, { call, put }) {
      yield put({ 
        type: 'saveModal',
        res
       });
    },
    /** 
     * 
    */
    *setAddModal({ res }, { call, put }) {
      yield put({ 
        type: 'saveAddModal',
        res
       });
    },
    /** 
     * 
    */
    *setSize({ res }, { call, put }) {
      yield put({ 
        type: 'saveSize',
        res
       });
    },
    /** 
     * 
    */
    *setDistributeModal({ res }, { call, put }) {
      yield put({ 
        type: 'saveDistributeModal',
        res
       }); 
    },
    /** 
     * 
    */
   *setOldDetailModal({ res }, { call, put }) {
      yield put({ 
        type: 'saveOldDetailModal',
        res:res.code === 200 ? Message.info('分配成功') : ''
      });
    },
    /** 
     * 
    */
   *setAreaInfo({ param },{call, put}) {
      const res =  yield call(selectDeptTree, {pageCurrent: 0, pageSize: 0});
      yield put({
        type: 'saveAreaInfo',
        res: res.code === 200 ? res.data : []
      });
    },
   /** 
     * 
    */
   *setServiceType({ param },{call, put}) {
      const res =  yield call(serviceTypeAll, {pageCurrent: 0, pageSize: 0});
      yield put({
        type: 'saveServiceType',
        res: res.code === 200 ? res.data.dataList : []
      });
    },
    /** 
     * 
    */
   *setServicePersons({ param },{call, put}) {
      const res =  yield call(getServicePeople, {pageCurrent: 0, pageSize: 0});
      yield put({
        type: 'saveServicePersons',
        res: res.code === 200 ? res.data.dataList : []
      });
    },
  /** 
     * 
    */
   *setGender({ param },{call, put}) {
      const res =  yield call(getGender, {});
      yield put({
        type: 'saveGender',
        res: res.code === 200 ? res.data : []
      });
    },
  },

  reducers: {
    save(state, action) {
      return { ...state, ...action.payload };
    },
    saveSize(state, { res }) {
      return { 
        ...state, 
        height: res.height,
        width: res.width,
      }
    },
    saveModal(state, { res }) { 
      return { 
        ...state, 
        personalModal: res,
      }
    },
    saveAddModal(state, { res }) { 
      return { 
        ...state, 
        addModal:res,
      }
    },
    saveDistributeModal(state, { res }) { 
      return { 
        ...state, 
        distributeModal:res,
      }
    },
    saveOldDetailModal(state, { res }) { 
      return { 
        ...state, 
        oldDetailModal:res,
      }
    },
    saveAreaInfo(state, { res }) {
      return {
        ...state,
        areaInfo: res
      }
    },
    saveServiceType(state, { res }) {
      return {
        ...state,
        serviceType: res
      }
    },
    saveServicePersons(state, { res }) {
      return {
        ...state,
        servicePersons: res
      }
    },
    saveGender(state, { res }) {
      return {
        ...state,
        gender: res
      }
    }
  },

};
